package com.ruoyi.resume.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.resume.domain.CvProjectExperience;
import com.ruoyi.resume.service.ICvProjectExperienceService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 项目经历Controller
 * 
 * @author ruoyi
 * @date 2024-05-31
 */
@RestController
@RequestMapping("/experience")
public class CvProjectExperienceController extends BaseController
{
    @Autowired
    private ICvProjectExperienceService cvProjectExperienceService;

    /**
     * 查询项目经历列表
     */
    @RequiresPermissions("resume:experience:list")
    @GetMapping("/list")
    public TableDataInfo list(CvProjectExperience cvProjectExperience)
    {
        startPage();
        List<CvProjectExperience> list = cvProjectExperienceService.selectCvProjectExperienceList(cvProjectExperience);
        return getDataTable(list);
    }

    /**
     * 导出项目经历列表
     */
    @RequiresPermissions("resume:experience:export")
    @Log(title = "项目经历", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CvProjectExperience cvProjectExperience)
    {
        List<CvProjectExperience> list = cvProjectExperienceService.selectCvProjectExperienceList(cvProjectExperience);
        ExcelUtil<CvProjectExperience> util = new ExcelUtil<CvProjectExperience>(CvProjectExperience.class);
        util.exportExcel(response, list, "项目经历数据");
    }



    /**
     * 获取项目经历详细信息
     */
    @RequiresPermissions("resume:experience:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cvProjectExperienceService.selectCvProjectExperienceById(id));
    }

    /**
     * 新增项目经历
     */
    @RequiresPermissions("resume:experience:add")
    @Log(title = "项目经历", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody List<CvProjectExperience>  cvProjectExperience)
    {
        return toAjax(cvProjectExperienceService.insertCvProjectExperience(cvProjectExperience));
    }

    /**
     * 修改项目经历
     */
    @RequiresPermissions("resume:experience:edit")
    @Log(title = "项目经历", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CvProjectExperience cvProjectExperience)
    {
        return toAjax(cvProjectExperienceService.updateCvProjectExperience(cvProjectExperience));
    }

    /**
     * 删除项目经历
     */
    @RequiresPermissions("resume:experience:remove")
    @Log(title = "项目经历", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cvProjectExperienceService.deleteCvProjectExperienceByIds(ids));
    }

    /**
     * 查询项目名称
     */
    @PostMapping("/getProjectName")
    public R getProjectName(@RequestParam String projectName)
    {

        return cvProjectExperienceService.getProjectName(projectName);
    }
}
